package team.pra.manager.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * 跨域设置
 */
@Configuration
public class GlobalConfig {
    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration configuration = new CorsConfiguration();
        //设置允许访问的网页
        configuration.addAllowedOrigin("http://127.0.0.1:8848");
        configuration.addAllowedOrigin("http://172.31.138.212:8848");
        configuration.addAllowedOrigin("http://localhost:63343");
        configuration.setAllowCredentials(true);
        //设置允许访问的方法
        configuration.addAllowedMethod("GET");
        configuration.addAllowedMethod("POST");
        //设置允许访问的请求头
        configuration.addAllowedHeader("*");
        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        //注册跨域配置
        configSource.registerCorsConfiguration("/**", configuration);
        return new CorsFilter(configSource);
    }
}
